package Square;

import java.math.BigDecimal;

import Border.BorderType;
import Border.Direction;

public class RegularSquare extends DefaultSquare{
	
	/**
	 * Creates a new RegularSquare
	 * 
	 * @param 	temperature
	 * 			The temperature for the new square
	 * @param 	humidity
	 * 			The humidity for the new square
	 * @param 	directions
	 * 			The directions to create a WALL border at
	 * @effect	This RegularSquare is initialized as a new DefaultSquare with given temperature and humidity
	 * 			| super(temperature, humidity)
	 * @post	The borders at given directions are set to BorderType.WALL
	 * 			| for (Direction direction : directions)
	 *			| 	this.getBorderAt(direction).getBorderType == BorderType.WALL
	 * @throws 	IllegalArgumentException
	 * 			No direction to place a border at is given
	 * 			| directions.length == 0
	 */
	public RegularSquare(double temperature, BigDecimal humidity,Direction... directions) throws IllegalArgumentException {
		super(temperature, humidity);
		if(directions.length == 0)
			 throw new IllegalArgumentException();
		for (Direction direction : directions)
			this.getBorderAt(direction).setBorderType(BorderType.WALL);	
	}

	/**
	 * @param	type
	 * 			The bordertype that the border will be set to
	 * @param	direction
	 * 			The direction of the border that will be modified
	 * @return	Returns false if the change will result in the square having no walls/doors
	 * 			Returns false if the change will result in the square having more then 3 doors
	 * 			Returns false if change results in adding a door in the floor
	 * 			Returns true in all other cases
	 * 			| if(countAmountOfBorders() == 1 && getBorderAt(direction).getBorderType() != BorderType.EMPTY && type == BorderType.EMPTY)
	 *			|	result == false
	 * 			| if (countAmountOfDoors() == 3 && !getBorderAt(direction).isDoor() && (type == BorderType.OPEN_DOOR || type == BorderType.CLOSED_DOOR))
	 *			| 	result == false
	 * 			| if((type == BorderType.OPEN_DOOR || type == BorderType.CLOSED_DOOR) && direction == Direction.FLOOR)
	 *			|	result == false
	 * 			| result == true
	 */
	@Override
	public boolean canHaveAsBorderType(BorderType type, Direction direction) {
		if(countAmountOfBorders() == 1 && getBorderAt(direction).getBorderType() != BorderType.EMPTY && type == BorderType.EMPTY)
			return false;
		else if	(countAmountOfDoors() == 3 && !getBorderAt(direction).isDoor() && (type == BorderType.OPEN_DOOR || type == BorderType.CLOSED_DOOR))
			return false;
		else if((type == BorderType.OPEN_DOOR || type == BorderType.CLOSED_DOOR) && direction == Direction.FLOOR)
			return false;
		else
			return true;
	}
		
}
